<?php

class ModelFilter
{
	private $baseModel;
	
	private $conditions = array();
	
	private $fields = false;
	
	function setBaseModel($model)
	{
		$this->baseModel = $model;
	}
	
	function setConditions($conditions)
	{
		$this->conditions = $conditions;
	}
	
	function setFields($fields)
	{
		$this->fields = am($fields, 'id');
	}
	
	function getModel()
	{
		$newModel = clone $this->baseModel;
		$newModel->noCallbackOverwrite = true;
		
		$newModel->setScope($this->conditions);
		
		if(!$this->fields)
		{
			return $newModel;
		}
		foreach($newModel->_schema as $field => $details)
		{
			if(!in_array($field, $this->fields))
			{
				unset($newModel->_schema[$field]);
			}
		}
		return $newModel;
	}
	
	
}

?>